const time = new Date();
const curYear = time.getFullYear();
const curMonth = time.getMonth() + 1;
const curDay = time.getDate();
	
export const getMonths = () => {
	/*填充月份*/
	let taryear = [];
	for(let i = 1; i <= 12; i++) {
		taryear.push({
			name: i,
			sub: [],
			type: 0
		});
	};
	return taryear;
}

const getMdaysNum = (Year, Month) => {
	/*获取指定年月的天数*/
	Month--;
	var d = new Date(Year, Month, 1);
	d.setDate(32);
	return(32 - d.getDate());
}

export const getMdays = (y, m) => {
	/*填充指定年月的日s*/
	let monthday = [];
	for(let i = 1; i <= getMdaysNum(y, m); i++) {
		monthday.push({
			name: i
		});
	};
	return monthday;
}

export const checkTime = (arr)=>{
	let newarr = arr.concat([]);
	let dayMax = getMdaysNum(curYear-20+arr[0],arr[1]+1)-1;
	newarr[2] = newarr[2]>dayMax?dayMax:newarr[2];
	return newarr;
}

export const getTime = (arr)=>{
	let time = {
		year:curYear-20+arr[0],
		month:arr[1]+1,
		day:arr[2]+1
	};
	let dayMax = getMdaysNum(time.year,time.month);
	time.day = time.day>dayMax?dayMax:time.day;
	return time;
}


export const yearInit = () => {
	/*初始化源数据*/
	let times = [{ name: curYear, sub: [], type: 1 }];
	times[0].sub = getMonths();
	times[0].sub[curMonth - 1].sub = getMdays(times[0].name, times[0].sub[curMonth - 1].name);
	for(let i = 1; i <= 20; i++) {
		times.push({
			name: curYear + i,
			sub: [],
			type: 1
		});
		times.unshift({
			name: curYear - i,
			sub: [],
			type: 1
		});
	};
	return times;
}
